Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the C program below.#include <std... Start Learning for Free
Consider the C program below.
#include <stdio.h> 
int *A, stkTop; 
int stkFunc (int opcode, int val) 

    static int size=0, stkTop=0; 
    switch (opcode) 
    { 
    case -1: 
        size = val; 
        break; 
    case 0: 
        if (stkTop < size ) A[stkTop++]=val; 
        break; 
    default: 
        if (stkTop) return A[--stkTop]; 
    } 
    return -1; 

int main() 

    int B[20]; 
    A=B; 
    stkTop = -1; 
    stkFunc (-1, 10); 
    stkFunc (0, 5); 
    stkFunc (0, 10); 
    printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0)); 
The value printed by the above program is ___________
  • a)
    15
  • b)
    10
  • c)
    27
  • d)
    9
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider the C program below.#include <stdio.h>int *A, stkTop;in...
The code in main, basically initializes a stack of size 10, then pushes 5, then pushes 10.
Finally the printf statement prints sum of two pop operations which is 10 + 5 = 15.
stkFunc (-1, 10); // Initialize size as 10 stkFunc (0, 5); // push 5
stkFunc (0, 10); // push 10
// print sum of two pop
printf ("%d\n", stkFunc(1, 0) + stkFunc(1, 0));
View all questions of this test
Most Upvoted Answer
Consider the C program below.#include <stdio.h>int *A, stkTop;in...
Understanding the Program
This C program implements a simple stack using a static array and a stack function. Here's a breakdown of its key components:
Global Variables
- `int *A, stkTop;` declares a pointer `A` that will point to an array and an integer `stkTop` to track the stack index.
Stack Function Logic
- The `stkFunc` function has three operations based on the `opcode`:
- -1: Initializes the stack size (`size`) to `val`.
- 0: Pushes `val` onto the stack if there's space.
- Default: Pops the top value from the stack if it's not empty.
Function Execution Steps
1. Initialization (`main`):
- `int B[20];` creates an array `B` of size 20.
- `A=B;` makes `A` point to the array `B`.
- `stkTop = -1;` sets the stack top to -1 (empty stack).
2. Set Stack Size:
- `stkFunc (-1, 10);` sets the stack size to 10.
3. Push Values:
- `stkFunc (0, 5);` pushes 5 onto the stack.
- `stkFunc (0, 10);` pushes 10 onto the stack.
Final Calculations
- The two calls to `stkFunc(1, 0)` pop values from the stack:
- First call: Pops 10 (stkTop becomes 0).
- Second call: Pops 5 (stkTop becomes -1).
- The sum of these two values is `10 + 5 = 15`.
Final Output
- The program prints `15`, confirming that the correct answer is option A.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Question Description
Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the C program below.#include <stdio.h>int *A, stkTop;int stkFunc (int opcode, int val){ static int size=0, stkTop=0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size ) A[stkTop++]=val; break; default: if (stkTop) return A[--stkTop]; } return -1;}int main(){ int B[20]; A=B; stkTop = -1; stkFunc (-1, 10); stkFunc (0, 5); stkFunc (0, 10); printf ("%d\n", stkFunc(1, 0)+ stkFunc(1, 0));}The value printed by the above program is ___________a)15b)10c)27d)9Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev